var Page = function(){
    this.init();
};
Page.prototype = {
    params: {
        passport: '',
        solutionId:''
    },
    init: function(){
        this.initParams();
        this.initEvent();
    },
    initParams: function(){
        this.params.passport = Pub.getCookie('_PASSPORT');
        this.params.solutionId = Pub.getSession('solutionId');
        $('#plaTitle').text('当前方案：'+Pub.getSession('soluName'));
    },
    getData: function(){
        var _this = this;
        var paramsObj = {
            passport: _this.params.passport,
            solutionId:_this.params.solutionId
        };
        Api.platformsolutiondetails(paramsObj, function(data){
            console.log(data);
            _this.getDataList(data.list,data.data.moduleId);
        });
    },
    getDataList:function(data,id){
        var _this = this;

        if (data && data.length>0) {
            var len=data.length/6;
            len=Math.ceil(len)
            var html='';
            for (var i = 0 ; i < len; i++) {
                html+= '<tr height="50">';
                for (var j = 0; j < 6; j++) {
                    if (data[(i*6+j)]) {
                        html+='<td >'+
                            '<div class="goods-checkbox mr-5">'+
                                '<div class="check-box" moduleId="'+data[(i*6+j)].moduleId+'">'+
                                   '<input moduleId="'+data[(i*6+j)].moduleId+'" name="new" type="checkbox">'+
                                '</div>'+
                            '</div>'+data[(i*6+j)].name+
                        '</td>';
                    }else{
                        html+='<td class=""></td>';
                    };
                };
            }
            $('#List').html(html);
            var moduleIdArr = id.split(",");
            $('input[name="new"]').each(function() {
                for (var i = 0; i < moduleIdArr.length; i++) {
                    if ($(this).attr('moduleId')==moduleIdArr[i]) {
                        $(this).iCheck('check');
                    };
                };
            });
            _this.getDataEvent();
        }else{
             $('#List').html('<tr><td colspan="6" class="text-c">暂无数据</td></tr>');
        };
    },
    getDataEvent:function(){
        var _this = this;
        $('.goods-checkbox input').iCheck({
            checkboxClass: 'icheckbox-blue',
            radioClass: 'iradio-blue',
            increaseArea: '20%'
        })
    },
    otherEvent:function(){
        var _this = this;
        $('#submit').click(function(event) {
            var arr=[];
            $('input[name="new"]:checked').each(function() {
                arr.push($(this).attr('moduleId'));
            });
            var moduleId=arr.join(',');
            console.log(moduleId);
            var paramsObj = {
                passport: _this.params.passport,
                solutionId:_this.params.solutionId,
                moduleId:moduleId
            };
            Api.platformsolutionmodify(paramsObj, function(data){
                console.log(data);
                layui.use('layer', function(){
                    layer.msg('编辑成功', {icon: 6});
                    setTimeout(function(){
                        window.location.href = Pub.getHtmlUrl('./platform-set.html');
                    },1500)
                });
            });
        });

    },
    initEvent: function(){
        var _this = this;
        _this.getData();
        _this.otherEvent();


    }
};
var page = new Page();